//这里编写业务通用的js
/**
 * 功能描述：考试类型选择
 */
var examTypelHref = "app/exam/examcategory/SelectItem/loadAjaxTree.do?rootId=4&&csId=4";
/**
 *功能描述：试卷分类
 */
var paperTypelHref = "app/exam/examcategory/SelectItem/loadAjaxTree.do?rootId=2&csId=2";
//选择题库
var bankHref = "app/exam/examcategory/SelectItem/loadBank.do";
//选择知识点
var pointHref = "app/exam/examcategory/SelectItem/loadPoint.do";
//选择机构
var groupHref = "app/exam/common/ExamSso/loadGroupTree.do";
//选择机构
function openGroupidWin(basePath, callBack, defaultValue) {
	var divId = "groupWin"
	var url = basePath + groupHref + "?callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	return openWin(url, divId, "width=400,height=450,left=300,top=220,status=no,resizable=yes,scrollbars=yes,menubar=no,toolbar=no");
}

function openGroupidDiv(elementP, basePath, callBack, defaultValue) {
	var divId = "groupWin"
	var url = basePath + groupHref + "?callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	// return openWin(url,divId,"width=400,height=450,left=300,top=220,status=no,resizable=yes,scrollbars=yes,menubar=no,toolbar=no");
	return createDivFrame(url, "选择机构", elementP, 400, 360)
}
/**
 * 功能描述：选择题库
 * @param basePath
 * @param callBack
 * @param defaultValue
 * @return
 */
function selectQuesBankWin(basePath, callBack, defaultValue) {
	var divId = "paperTypeWin"
	var url = basePath + bankHref + "?callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	var style = "width=820,height=480,left=200,top=120,status=no,resizable=yes,scrollbars=auto,menubar=no,toolbar=no";
	return openWinBlock(url, divId, style);
}
/**
 * 功能描述：选择知识点
 * @param basePath
 * @param callBack
 * @param defaultValue
 * @return
 */
function selectKnowledgeWin(basePath, callBack, defaultValue) {
	var divId = "pointWin"
	var url = basePath + pointHref + "?callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	var style = "width=820,height=480,left=200,top=120,status=no,resizable=yes,scrollbars=auto,menubar=no,toolbar=no";
	return openWinBlock(url, divId, style);
}

function openPaperTypeWin(basePath, callBack, defaultValue) {
	var divId = "paperTypeWin"
	var url = basePath + paperTypelHref + "&callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	return openWinBlock(url, divId);
}

function openPaperPTypeDiv(element, basePath, callBack, defaultValue) {
	var divId = "paperTypeDiv"
	var url = basePath + paperTypelHref + "&callBack=" + callBack + "&defaultValue=" + encodpeURIComponent(defaultValue);
	return singleSelectDialog(url, "选择考试类型", element, divId);
}

function openExamTypeWin(basePath, callBack, defaultValue) {
	var divId = "examTypeWin"
	var url = basePath + examTypelHref + "&callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	return openWinBlock(url, divId);
}

function openExamTypeDiv(element, basePath, callBack, defaultValue) {
	var divId = "examTypeDiv"
	var url = basePath + examTypelHref + "&callBack=" + callBack + "&defaultValue=" + encodeURIComponent(defaultValue);
	//return createDivFrame(url,"选择考试类型",element,"300","200");
	return createDivFrame(url, "选择考试类型", element, "300", "200");
}

/**
 * 功能描述：查看用户信息
 * @param userId
 * @return
 */
function _seeUserInfo(userId) {
	var url = js_basePath + "app/appsecurity/user/User/show.do?noShowBtn=1&userId=" + userId;
	// createDivFrame(url,"查看用户信息",null,660,400);
	window.open(url);
}
/*
function _seeUserInfo(basePath, userId){
	   var url = basePath + "app/appsecurity/User/show.do?noShowBtn=1&id=" + userId;
     createDivFrame(url,"查看用户信息",null,660,400);
}
*/
//选择科目
function getPopupSubject(formNameP, inputNameP, basePath) {
	var params = {
		inputName: inputNameP,
		formName: formNameP,
		title: '选择科目',
		url: basePath + 'app/exam/examcategory/ExamCategoryItem/selectSubjectList.do?rootId=5&csId=5',
		width: '600',
		height: '550'
	};
	var subjectIdSelect = new popupSelect(params);
	return subjectIdSelect;
}
//选择机构
function getPopupGroup(formNameP, inputNameP, basePath) {
	var params = {
		inputName: inputNameP,
		formName: formNameP,
		title: '选择机构',
		url: basePath + groupHref,
		width: '400',
		height: '360'
	};
	var subjectIdSelect = new popupSelect(params);
	return subjectIdSelect;
}
//收起、隐藏高级查询条件
function showExtQuery(thObj) {
	var extQueryDiv = document.getElementById("extQueryDiv");
	var displayValue = extQueryDiv.style.display;
	var moreSearchConditions = document.getElementById('moreSearchConditions');
	if (displayValue == "none") {
		extQueryDiv.style.display = "block";
		thObj.innerHTML = '隐藏';
		if (moreSearchConditions != null) {
			moreSearchConditions.value = '1';
		}
	} else {
		extQueryDiv.style.display = "none";
		thObj.innerHTML = '更多条件';
		if (moreSearchConditions != null) {
			moreSearchConditions.value = '0';
		}
	}
}

function _down(basePath, filePath, fileNameP) {
	if (filePath) {
		filePath = filePath.substring(filePath.indexOf("upload"), filePath.length);
	}
	downFile(basePath, filePath, fileNameP);
}
/**
 * 下载文件   注：在页面中需添加：<iframe id="_downIframe"  src="blank.html" style="display:none"></iframe>
 * @param {} basePath 项目请求路径
 * @param {} filePath 相对于application.properties中属性fileDownBaseDir的文件路径
 * @param {} fileNameP 下载后的文件名
 */
function downFile(basePath, filePath, fileNameP) {
	var date = new Date();
	var fileName = "";
	if (fileNameP) {
		fileName = fileNameP;
	}
	var params = "?filePath=" + encodeURIComponent(filePath) + "&fileName=" + encodeURIComponent(fileName) + "&date=" + date.getTime();
	var downUrl = basePath + "framework/file/down.do" + params;
	document.getElementById("_downIframe").src = downUrl;
}

/* 窗口对象，避免重复打开多个学课窗口 */
var classroomWin;
/* 打开一个可设置大小及滚动条的窗口 */
function _openSizedWindowCenter(url, winName, width, height, scrollbars) {
	xposition = 0;
	yposition = 0;
	if ((parseInt(navigator.appVersion) >= 4)) {
		//xposition = (screen.width - width) / 2;
		xposition = (window.screen.availWidth - width) / 2;
		yposition = (window.screen.availHeight - height) / 2;
	}
	if (yposition > 30) yposition = 30;
	theproperty = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=yes," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
	if (scrollbars == 'false')
		theproperty += ",scrollbars=no";
	else
		theproperty += ",scrollbars=yes";
	window.open(url);
}

/* 打开一个可设置滚动条的全屏窗口不刷新父窗口 */
function _openFullWindowCenterNoFresh(url, winName, scrollbars) {
	if (typeof(classroomWin) != 'undefined') {
		classroomWin.close();
	}
	var width = window.screen.availWidth;
	var height = window.screen.availHeight;
	var xposition = 0;
	var yposition = 0;
	xposition = (window.screen.availWidth - width) / 2;
	yposition = (window.screen.availHeight - height) / 2;
	if (yposition > 30) yposition = 30;
	theproperty = "width=" + width + "," + "height=" + height + "," + "location=no," + "menubar=0," + "resizable=no," + "status=0," + "titlebar=0," + "toolbar=no," + "hotkeys=0,Direction=no,Resizeable=no" + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
	if (scrollbars == 'false')
		theproperty += ",scrollbars=no";
	else
		theproperty += ",scrollbars=yes";
	classroomWin = window.open(url);
}

/* 打开一个可设置滚动条的全屏窗口 可以回调刷新窗口*/
function _openFullWindowCenter(url, winName, scrollbars, title) {
	if (typeof(classroomWin) != 'undefined') {
		classroomWin.close();
	}
	var width = window.screen.availWidth;
	var height = window.screen.availHeight;
	var xposition = 0;
	var yposition = 0;
	xposition = (window.screen.availWidth - width) / 2;
	yposition = (window.screen.availHeight - height) / 2;
	if (yposition > 30) yposition = 30;
	theproperty = "width=" + width + "," + "height=" + height + "," + "location=no," + "menubar=0," + "resizable=no," + "status=0," + "titlebar=0," + "toolbar=no," + "hotkeys=0,Direction=no,Resizeable=no" + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
	if (scrollbars == 'false')
		theproperty += ",scrollbars=no";
	else
		theproperty += ",scrollbars=yes";
	classroomWin = window.open(url);
	if (typeof(title) != 'undefined') {
		$.confirm({
			'title': '请确认',
			'message': title,
			'buttons': {
				'确定': {
					'class': 'blue',
					'action': function() {
						//...refresh...hide
						//$.confirm.refresh();
						window.location.reload();
						//window.location.href=window.location.href;
					}
				}
				//'取消'	: {
				//	'class'	: 'gray',
				//	'action': function(){
				//		$.confirm.hide();
				//	}
				//}
			}
		});
	}
}
/** 将 秒数 转换为 易读 形式 */
function _createdString(seconds) {
	var sb = "";
	if (seconds > 3600 * 24 * 30 * 3)
		sb += "3个月前";
	else if (seconds > 3600 * 24 * 30 * 1)
		sb += "1个月前";
	else if (seconds > 3600 * 24 * 20)
		sb += "20天前";
	else if (seconds > 3600 * 24 * 10)
		sb += "10天前";
	else if (seconds > 3600 * 24 * 3)
		sb += "3天前";
	else if (seconds > 3600 * 24)
		sb += "1天前";
	else if (seconds > 3600)
		sb += Math.round(seconds / 3600) + "小时前";
	else if (seconds > 60)
		sb += Math.round(seconds / 60) + "分钟前";
	else
		sb += "刚刚";
	return sb;
}